//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "fBlurAdvancedC.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "GLS.BaseClasses"
#pragma link "GLS.Blur"
#pragma link "GLS.Cadencer"
#pragma link "GLS.Coordinates"

#pragma link "GLS.GeomObjects"
#pragma link "GLS.HUDObjects"
#pragma link "GLS.Material"
#pragma link "GLS.Objects"
#pragma link "GLS.Scene"
#pragma link "GLS.SceneViewer"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{

 // TFileName AssetsPath = TFileName Path = GetCurrentAssetPath();
 //  SetCurrentDir(AssetsPath);
 String AssetsPath = ExtractFilePath(ParamStr(0));
  int I = AssetsPath.Pos("Demos");
  if (I != 0) {
	AssetsPath.Delete(I+7, AssetsPath.Length() - (I+5));
	AssetsPath += "Assets\\";
	SetCurrentDir(AssetsPath);
  }

  // Blur GLDummyCube1 and it's children
  GLBlur1->TargetObject = GLDummyCube1;
  // point to GLDummyCube1
  GLCamera1->TargetObject = GLDummyCube1;
  // load materials
  GLMaterialLibrary1->Materials->Items[0]->Material->Texture->Image->LoadFromFile("beigemarble.jpg");
  GLMaterialLibrary1->Materials->Items[1]->Material->Texture->Image->LoadFromFile("moon.bmp");

}
//---------------------------------------------------------------------------
void __fastcall TForm1::GLBlur1BeforeTargetRender(TObject *Sender)
{
     TorusImpostor->Visible = true; // GLBlur1 must render the Torusimpostor
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GLBlur1AfterTargetRender(TObject *Sender)
{
     TorusImpostor->Visible = false; // GLSCeneViewer1 must NOT render the Torusimpostor
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
          const double newTime)
{
     GLSceneViewer1->Invalidate();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
		  int X, int Y)
{
	 if (Shift.Contains(ssRight) && (Y > 10))
		GLCamera1->AdjustDistanceToTarget(my/Y);
	 if (Shift.Contains(ssLeft))
		GLCamera1->MoveAroundTarget(my-Y,mx-X);
	 mx = X;
	 my = Y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
	 LabelFPS->Caption  = GLSceneViewer1->FramesPerSecondText(0);
	 GLSceneViewer1->ResetPerformanceMonitor();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::trkAdvancedBlurHiClampChange(TObject *Sender)
{
	 GLBlur1->AdvancedBlurHiClamp = trkAdvancedBlurHiClamp->Position;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::trkAdvancedBlurLoClampChange(TObject *Sender)
{
	 GLBlur1->AdvancedBlurLowClamp = trkAdvancedBlurLoClamp->Position;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::edtAdvancedBlurAmpChange(TObject *Sender)
{
	 GLBlur1->AdvancedBlurAmp = StrToFloat(edtAdvancedBlurAmp->Text);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::edtAdvancedBlurPassesChange(TObject *Sender)
{
     GLBlur1->AdvancedBlurPasses = StrToInt(edtAdvancedBlurPasses->Text);
}
//---------------------------------------------------------------------------
